package com.xhdx;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.Charset;

public class CharsetTest {

    public static void main(String[] args) {
        System.out.println("当前JRE：" + System.getProperty("java.version"));
        System.out.println("当前JVM的默认字符集：" + Charset.defaultCharset());
        
        if(new String("java").equals(new String("java"))){
            System.out.println(true);
        }else{
            System.out.println(false);
        }
        String s = "<Sign>8488C54880BB27A77C22BFED07744192</Sign></root><InterfaceName>007KA_B2B</InterfaceName><TranInfo>´úÀíÉÌÐ£Ñé´í</TranInfo><ChgerName>å¼ æ§</ChgerName><ChgerName>%E5%BC%A0%E8%81%AA</ChgerName>";
        try {
            System.out.println(new String(s.getBytes("ISO-8859-1"),Charset.forName("GB2312")));
            System.out.println(new String(s.getBytes(),Charset.forName("GB2312")));
            System.out.println(new String(s.getBytes("UTF-8"),Charset.forName("GB2312")));
            System.out.println(new String(s.getBytes("GB2312"),Charset.forName("GB2312")));
            System.out.println(new String(s.getBytes("ISO-8859-1"),Charset.forName("GBK")));
            System.out.println(URLDecoder.decode(new String(s.getBytes("ISO-8859-1"),Charset.forName("GB2312")),"UTF-8"));
            System.out.println(URLEncoder.encode(new String("&aa=uiop&MerAccount=张聪"),"UTF-8"));
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("=============================");
        String p = "<ChgerName>å¼ æ§</ChgerName>";
        try {
            String p1 = new String(p.getBytes("ISO-8859-1"),Charset.forName("UTF-8"));
            System.out.println(p1);
            System.out.println(new String(p1.getBytes(),Charset.forName("UTF-8")));
            
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        System.out.println("=============================");
        String xml = "<TranInfo>??????</TranInfo>";
        try {
            String p1 = new String(xml.getBytes("ISO-8859-1"),Charset.forName("UTF-8"));
            System.out.println(xml);
            System.out.println(new String(xml.getBytes("UTF-8"),Charset.forName("GB2312")));
            
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
